var redis = require("redis"),
	client = redis.createClient();

client.on("error", function(err) {
	console.log("Error" + err);
});

// client.on("connect", runSample);
client.on("connect", sampleExpire);

function runSample() {
	client.set("string_key", "hello world", function(err, reply) {
		console.log(reply.toString());
	});

	client.get("string_key", function(err, reply) {
		console.log(reply.toString());
	});
}

function sampleExpire() {
	client.set("key_abc", "hello world", redis.print);
	client.expire("key_abc", 3);
	var myTimer = setInterval(function() {
		client.get("key_abc", function(err, reply) {
			if (reply) {
				console.log("I live:" + reply.toString());
			} else {
				clearTimeout(myTimer);
				console.log("I expired");
				client.quit();
			}
		});
	}, 1000);
}